package dBConnection;

import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JOptionPane;

public class GRIAdBUpdater extends Thread {
	public static GRIAdBUpdater singleton;
	String url;
	String dbName;
	String user;
	String pwd;
	String driver;
	private Timer timer;

	public void run() {

		this.timer = new Timer();
		TimedUpdateTask task = new TimedUpdateTask(this.url, this.dbName,
				this.user, this.pwd, this.driver);
		//every 3 days
		this.timer.schedule(task, 0, 1000*60*60*24*3);
	}

	public static GRIAdBUpdater getInstance(String url, String dbName,
			String user, String pwd, String driver) {
		if (GRIAdBUpdater.singleton == null) {
			try {
				GRIAdBUpdater.singleton = new GRIAdBUpdater(url, dbName, user,
						pwd, driver);
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			GRIAdBUpdater.singleton.start();
			return GRIAdBUpdater.singleton;
		} else 
			return GRIAdBUpdater.singleton;
		
	}

	private GRIAdBUpdater(String url, String dbName, String user, String pwd,
			String driver) throws ClassNotFoundException {
		this.url = url;
		this.dbName = dbName;
		this.user = user;
		this.pwd = pwd;
		this.driver = driver;

	}

}
